<?php
declare(strict_types=1);

namespace App\Resource\Group\Members;


use App\Enums\GroupEnum;
use Illuminate\Http\Resources\Json\JsonResource;

class Resource extends JsonResource
{
    public function toArray($request)
    {
        if(empty($this->id)){
            return [];
        }
        $avatar = $this->user->user_data->head_picture;
        //交友群展示默认头像
        if (!empty($this->group->category->type) && $this->group->category->type == GroupEnum::GROUP_CATEGORY_TYPE_FRIEND){
            $avatar = '';
        }
        return [
            "id" => $this->user_id,
            "role" => $this->role,
            // "nickname" => $this->nickname,
            "nickname" => $this->nickname ?: $this->user->user_data->nickname, // 优先展示群备注
            "avatar" => $avatar,
            "gender" => $this->user->user_data->sex,
            "grade" => empty($this->user->grade) ? 0 : $this->user->grade->id,
            "grade_icon" => empty($this->user->grade) ? "" : $this->user->grade->head_picture,
        ];
    }
}